//2020-12-18T16:51:56+08:00 时间转换函数
export function resetForm(fmt, date) {
  let ret = "";
  date = new Date(date);
  const opt = {
    'Y+': date.getFullYear().toString(), // 年
    'm+': (date.getMonth() + 1).toString(), // 月
    'd+': date.getDate().toString(), // 日
    'H+': date.getHours().toString(), // 时
    'M+': date.getMinutes().toString(), // 分
    'S+': date.getSeconds().toString() // 秒
    // 有其他格式化字符需求可以继续添加，必须转化成字符串
  }
  for (let k in opt) {
    ret = new RegExp('(' + k + ')').exec(fmt)
    if (ret) {
      fmt = fmt.replace(
        ret[1],
        ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0')
      )
    }
  }
  return fmt

}
//时间戳转正常格式
export function timestampToTime(timestamp) {
  var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = date.getDate() < 10 ? "0" + date.getDate() + " " : date.getDate() + " ";
  var h =
    date.getHours() < 10
      ? "0" + date.getHours() + ":"
      : date.getHours() + ":";
  var m =
    date.getMinutes() < 10
      ? "0" + date.getMinutes() + ":"
      : date.getMinutes() + ":";
  var s =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return Y + M + D + h + m + s;
}


//时间戳转正常格式  不显示时分秒
export function timestampToTimeno(timestamp) {
  var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = date.getDate() < 10 ? "0" + date.getDate() + " " : date.getDate() + " ";
  var h =
    date.getHours() < 10
      ? "0" + date.getHours() + ":"
      : date.getHours() + ":";
  var m =
    date.getMinutes() < 10
      ? "0" + date.getMinutes() + ":"
      : date.getMinutes() + ":";
  var s =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return Y + M + D;
}


export function matchaTypeImg(filePath) {
  var index = filePath.lastIndexOf(".");
  var ext = filePath.substr(index + 1);
  var resultl = "";
  var imgList = ["png", "jpg", "bmp", "jpeg", "gif"];
  resultl = imgList.some(function (item) {
    return item == ext;
  });
  if (filePath.indexOf("auth_key") != -1) {
    if (filePath.indexOf("x-oss-process") != -1) {
      return filePath + ",w_200,h_300";
    } else {
      return filePath + "&x-oss-process=image/resize,w_200,h_300";
    }
  } else {
    if (filePath.indexOf("x-oss-process") != -1) {
      return filePath + ",w_200,h_300";
    } else {
      return filePath + "?x-oss-process=image/resize,w_200,h_300";
    }
  }
}